import time

from watchers.etcd_watcher import put_etcd_watch_key
from watchers.redis_pub_sub import publish_refresh_event
from watchers.redis_streams import publish_refresh_event_streams
from watchers.consul_watcher import write_consul_notify
from watchers.nacos_listener import publish_update_signal
from model.db.name_mapping import (
    get_name_by_type, update_name_by_type_from_db,
    NAME_TYPE_STUDENT, NAME_TYPE_CLASS, NAME_TYPE_SCHOOL, NAME_TYPE_TEAM,
)


def get_student_name():
    return get_name_by_type(NAME_TYPE_STUDENT)


def get_class_name():
    return get_name_by_type(NAME_TYPE_CLASS)


def get_school_name():
    return get_name_by_type(NAME_TYPE_SCHOOL)


def get_team_name():
    return get_name_by_type(NAME_TYPE_TEAM)


def update_name_by_type(name_type: str, new_name: str):
    """
    根据 name_type 更新数据库中的 name，并通知 etcd 更新缓存
    """
    # 更新数据库数据
    update_name_by_type_from_db(name_type, new_name)

    # Notice 通知 etcd 更新缓存
    # put_etcd_watch_key()

    # Notice 通知 consul 更新缓存
    # write_consul_notify()

    # Notice 更新nacos配置 触发缓存更新
    # publish_update_signal()

    # Notice 往redis发布refresh消息
    publish_refresh_event(name_type)

    # Notice 往redis的streams中推送消息
    # publish_refresh_event_streams(name_type)
